package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"grpc_starter/grpc_demo/proto"
)

type client struct {
}

func main() {
	conn, err := grpc.Dial("127.0.0.1:5000", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	defer func(conn *grpc.ClientConn) {
		err := conn.Close()
		if err != nil {
			panic(err)
		}
	}(conn)

	client := proto.NewHelloServiceClient(conn)

	helloRes, err := client.SayHello(context.Background(), &proto.HelloReq{
		Msg: "client send data",
	})
	if err != nil {
		panic(err)
	}

	fmt.Println("The client gets the data sent by the server of function name is sayHello: ", helloRes.Msg)

	nameRes, err := client.SayName(context.Background(), &proto.NameReq{Name: "name function client sent data"})
	if err != nil {
		panic(err)
	}
	fmt.Println("The client gets the data sent by the server of function name: ", nameRes.Name)

	userInfo, _ := client.GetUserInfo(context.Background(), &proto.UserReq{
		UserId: "10",
	})
	fmt.Println("getUserInfo from server got data is: ", userInfo)

}
